/**
 * 
 */
package server.internal;

import static commons.Preconditions.checkNotNull;
import server.StorageUnitID;

/**
 * @author armstrong
 * 
 */
public class DefaultStorageUnitID implements StorageUnitID {

	public static StorageUnitID createId(final String id) {

		return new DefaultStorageUnitID(id);
	}

	private final String	id;

	private DefaultStorageUnitID(final String id) {

		checkNotNull("id is null.", id);

		this.id = id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final DefaultStorageUnitID other = (DefaultStorageUnitID) obj;
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see server.StorageUnitId#getId()
	 */
	@Override
	public String getId() {

		return id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

}
